
******************************************************************************
**************** prepare BACI data *******************************************
******************************************************************************


/*csv-files were downloaded from http://www.cepii.fr/cepii/en/bdd_modele/presentation.asp?id=1*/
cd "/Users/inga/Dropbox/Ais project/Repository"

global baci "/Users/inga/Dropbox/Ais project/Repository/data_input/BACI"


import delim using "$baci/country_code_baci12", clear
drop iso2
replace iso3 = "BLX" if i==58
replace iso3 = "SAC" if i==711
save "$baci/countrycodes", replace

import delim using "$baci/baci12_2016.csv", varnames(1) clear

merge m:1 i using "$baci/countrycodes"
drop if _merge==1 /*St. Barthelemy not found*/
drop _merge
rename i i2
rename j i
rename iso3 iso_i

merge m:1 i using "$baci/countrycodes"
drop if _merge==1 /*St. Barthelemy not found*/
drop _merge
rename i j
rename i2 i
rename iso3 iso_j

drop if iso_i=="NULL"
drop if iso_j=="NULL"

gcollapse (sum) v, by(iso* t) fast

save "$baci/baci2016_bil", replace
